package com.google.code.coma.rmi;

import com.google.code.coma.domain.Part;
import com.google.code.coma.domain.Type;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Bernie
 * Date: 10.01.12
 * Time: 20:44
 * To change this template use File | Settings | File Templates.
 */
public class TypeAmountPartSelector implements EntrySelector<Part> {
    private int amount;
    private Type type;

    public TypeAmountPartSelector(int amount, Type type) {
        this.amount = amount;
        this.type = type;
    }

    @Override
    public List<Part> selectEntries(List<Part> allEntries) throws SelectionException {
        List<Part> selectedEntries = new ArrayList<Part>();

        for (Part part : allEntries) {
            if (part.getType().equals(type)) {
                selectedEntries.add(part);
            }

            if (selectedEntries.size() == amount) {
                return selectedEntries;
            }
        }

        return selectedEntries;
    }
}
